<?php

namespace App\Listeners;

class QueryListener {
  /**
   * Create the event listener.
   *
   * @return void
   */
  public function __construct() {
    //
  }

  /**
   * Handle the event.
   *
   * @param \Illuminate\Database\Events\QueryExecuted $event
   *
   * @return void
   */
  public function handle( $event ) {
    //if ( env( 'APP_ENV', 'production' ) == 'local' ) {
      foreach ( $event->bindings as $index => $param ) {
        if ( $param instanceof DateTime ) {
          $event->bindings[ $index ] = $param->format( 'Y-m-d H:i:s' );
        }
      }
      $sql = str_replace( "?", "'%s'", $event->sql );
      array_unshift( $event->bindings, $sql );
      \Log::info( call_user_func_array( 'sprintf', $event->bindings) );
   // }

  }

}
